library("tidyverse")
library("firatheme")
library("estimatr")
library("prediction")

# load data
load("~/df_replication.RData")

# Table SI2
summary(model1 <- lm_robust(click ~ cue, data = df_replication, se_type="HC2"))

# Table SI3
summary(model2 <- lm_robust(click ~ issue, data = df_replication, se_type="HC2"))

# Table SI4
summary(model5 <- lm_robust(click ~ cue + issue + region + party_name, data = df_replication, se_type="HC2"))

# Table SI5
summary(model6 <- lm_robust(click ~ cue*issue + region + party_name, data = df_replication, se_type="HC2"))


# Figure SI 6 - upper panel
df_replication$block <- ifelse(df_replication$party_name == "Dansk Folkeparti" | 
                                 df_replication$party_name == "Konservative" |
                                 df_replication$party_name == "Liberal Alliance" |
                                 df_replication$party_name == "Nye Borgerlige" |
                                 df_replication$party_name == "Venstre", "blue", "red")


summary(model_block1 <- lm_robust(click ~ block*cue, data = df_replication, se_type="HC2"))

a <- prediction(model_block1, at = list(cue = "public_opinion", block = "blue"))
b <- prediction(model_block1, at = list(cue = "public_opinion", block = "red"))
c <- prediction(model_block1, at = list(cue = "rival_parties", block = "blue"))
d <- prediction(model_block1, at = list(cue = "rival_parties", block = "red"))
e <- prediction(model_block1, at = list(cue = "the_media", block = "blue"))
f <- prediction(model_block1, at = list(cue = "the_media", block = "red"))
g <- prediction(model_block1, at = list(cue = "problem_indicators", block = "blue"))
h <- prediction(model_block1, at = list(cue = "problem_indicators", block = "red"))


figure <- tibble(
  Block = c("Blue", "Red", "Blue","Red", "Blue","Red", "Blue","Red"),
  Treatment = c("Public Opinion", "Public Opinion", "Party Positions", "Party Positions", "Media Reporting", "Media Reporting", "Problem Indicators","Problem Indicators"),
  avg = c(mean(a$fitted)*100, mean(b$fitted)*100, mean(c$fitted)*100, mean(d$fitted)*100, mean(e$fitted)*100, mean(f$fitted)*100, mean(g$fitted)*100, mean(h$fitted)*100), 
  lower = c(mean(a$fitted)*100 - mean(a$se.fitted)*100, mean(b$fitted)*100 - mean(b$se.fitted)*100, mean(c$fitted)*100 - mean(c$se.fitted)*100, mean(d$fitted)*100 - mean(d$se.fitted)*100, mean(e$fitted)*100 - mean(e$se.fitted)*100, mean(f$fitted)*100 - mean(f$se.fitted)*100, mean(g$fitted)*100 - mean(g$se.fitted)*100, mean(h$fitted)*100 - mean(h$se.fitted)*100),
  upper = c(mean(a$fitted)*100 + mean(a$se.fitted)*100, mean(b$fitted)*100 + mean(b$se.fitted)*100, mean(c$fitted)*100 + mean(c$se.fitted)*100, mean(d$fitted)*100 + mean(d$se.fitted)*100, mean(e$fitted)*100 + mean(e$se.fitted)*100, mean(f$fitted)*100 + mean(f$se.fitted)*100, mean(g$fitted)*100 + mean(g$se.fitted)*100, mean(h$fitted)*100 + mean(h$se.fitted)*100))


ggplot(figure, aes(x= reorder(Treatment,-avg), y=avg, fill=Block)) +
  geom_bar(stat="identity", position="dodge", color= "black", width=.25) +
  geom_linerange(aes(ymin=lower, ymax=upper), position= position_dodge(.25)) +
  geom_text(aes(y=upper, label=round(avg,1)), size = 3, position=position_dodge(width=0.7), vjust=-1.75)+
  labs(y="Click Rate (%)", x="", title="", caption = "Note: Error bars represent ± 1 standard error (HC2)", size = 4)+
  scale_fill_manual(values=c("blue","red", "blue","red")) + 
  scale_y_continuous(limits = c(0, 45)) + theme_fira() + 
  theme(text = element_text(size=8), legend.position= "bottom", plot.caption = element_text(size = 6, color = "gray40", face = "italic"))

# Figure SI 6 - lower panel
summary(model_block2 <- lm_robust(click ~ block*issue, data = df_replication, se_type="HC2"))

a <- prediction(model_block2, at = list(issue = "school", block = "blue"))
b <- prediction(model_block2, at = list(issue = "climate", block = "blue"))
c <- prediction(model_block2, at = list(issue = "school", block = "red"))
d <- prediction(model_block2, at = list(issue = "climate", block = "red"))

figure <- tibble(
  Block = c("Blue","Blue","Red", "Red"),
  Problem = c("Public Schools","Climate Change","Public Schools", "Climate Change"),
  avg = c(mean(a$fitted)*100, mean(b$fitted)*100, mean(c$fitted)*100, mean(d$fitted)*100), 
  lower = c(mean(a$fitted)*100 - mean(a$se.fitted)*100, mean(b$fitted)*100 - mean(b$se.fitted)*100, mean(c$fitted)*100 - mean(c$se.fitted)*100, mean(d$fitted)*100 - mean(d$se.fitted)*100),
  upper = c(mean(a$fitted)*100 + mean(a$se.fitted)*100, mean(b$fitted)*100 + mean(b$se.fitted)*100, mean(c$fitted)*100 + mean(c$se.fitted)*100, mean(d$fitted)*100 + mean(d$se.fitted)*100))

ggplot(figure, aes(x= reorder(Problem,-avg), y=avg, fill=Block)) +
  geom_bar(stat="identity", position="dodge", color= "black", width=.25) +
  geom_linerange(aes(ymin=lower, ymax=upper), position= position_dodge(.25)) +
  geom_text(aes(y=upper, label=round(avg,1)), size = 3, position=position_dodge(width=0.7), vjust=-1.75)+
  labs(y="Click Rate (%)", x="", title="", caption = "Note: Error bars represent ± 1 standard error (HC2)", size = 4)+
  scale_fill_manual(values=c("blue","red", "blue","red")) + 
  scale_y_continuous(limits = c(0, 35)) + theme_fira() + 
  theme(text = element_text(size=8), legend.position= "bottom", plot.caption = element_text(size = 6, color = "gray40", face = "italic"))


#Figure SI 7 - upper panel
summary(model_blue <- lm_robust(click ~ cue*party_name, data = df_replication, se_type="HC2"))

# blue parties
a <- prediction(model_blue, at = list(cue = "public_opinion", party_name = "Venstre"))
b <- prediction(model_blue, at = list(cue = "public_opinion", party_name = "Konservative"))
c <- prediction(model_blue, at = list(cue = "public_opinion", party_name = "Dansk Folkeparti"))
d <- prediction(model_blue, at = list(cue = "public_opinion", party_name = "Liberal Alliance"))
e <- prediction(model_blue, at = list(cue = "public_opinion", party_name = "Nye Borgerlige"))

f <- prediction(model_blue, at = list(cue = "rival_parties", party_name = "Venstre"))
g <- prediction(model_blue, at = list(cue = "rival_parties", party_name = "Konservative"))
h <- prediction(model_blue, at = list(cue = "rival_parties", party_name = "Dansk Folkeparti"))
i <- prediction(model_blue, at = list(cue = "rival_parties", party_name = "Liberal Alliance"))
j <- prediction(model_blue, at = list(cue = "rival_parties", party_name = "Nye Borgerlige"))

k <- prediction(model_blue, at = list(cue = "the_media", party_name = "Venstre"))
l <- prediction(model_blue, at = list(cue = "the_media", party_name = "Konservative"))
m <- prediction(model_blue, at = list(cue = "the_media", party_name = "Dansk Folkeparti"))
n <- prediction(model_blue, at = list(cue = "the_media", party_name = "Liberal Alliance"))
o <- prediction(model_blue, at = list(cue = "the_media", party_name = "Nye Borgerlige"))

p <- prediction(model_blue, at = list(cue = "problem_indicators", party_name = "Venstre"))
q <- prediction(model_blue, at = list(cue = "problem_indicators", party_name = "Konservative"))
r <- prediction(model_blue, at = list(cue = "problem_indicators", party_name = "Dansk Folkeparti"))
s <- prediction(model_blue, at = list(cue = "problem_indicators", party_name = "Liberal Alliance"))
t <- prediction(model_blue, at = list(cue = "problem_indicators", party_name = "Nye Borgerlige"))

figure <- tibble(
  Party = c("Venstre", "Konservative", "Dansk Folkeparti", "Liberal Alliance", "Nye Borgerlige", "Venstre", "Konservative", "Dansk Folkeparti", "Liberal Alliance", "Nye Borgerlige", "Venstre", "Konservative", "Dansk Folkeparti", "Liberal Alliance", "Nye Borgerlige", "Venstre", "Konservative", "Dansk Folkeparti", "Liberal Alliance", "Nye Borgerlige"),
  Treatment = c("Public Opinion", "Public Opinion", "Public Opinion", "Public Opinion", "Public Opinion", "Party Positions", "Party Positions", "Party Positions", "Party Positions", "Party Positions", "Media Reporting", "Media Reporting", "Media Reporting", "Media Reporting","Media Reporting",  "Problem Indicators","Problem Indicators", "Problem Indicators","Problem Indicators", "Problem Indicators"),
  avg = c(mean(a$fitted)*100, mean(b$fitted)*100, mean(c$fitted)*100, mean(d$fitted)*100, mean(e$fitted)*100, mean(f$fitted)*100, mean(g$fitted)*100, mean(h$fitted)*100, mean(i$fitted)*100, mean(j$fitted)*100, mean(k$fitted)*100, mean(l$fitted)*100, mean(m$fitted)*100, mean(n$fitted)*100, mean(o$fitted)*100, mean(p$fitted)*100, mean(q$fitted)*100, mean(r$fitted)*100, mean(s$fitted)*100, mean(t$fitted)*100), 
  lower = c(mean(a$fitted)*100 - mean(a$se.fitted)*100, mean(b$fitted)*100 - mean(b$se.fitted)*100, mean(c$fitted)*100 - mean(c$se.fitted)*100, mean(d$fitted)*100 - mean(d$se.fitted)*100, mean(e$fitted)*100 - mean(e$se.fitted)*100, mean(f$fitted)*100 - mean(f$se.fitted)*100, mean(g$fitted)*100 - mean(g$se.fitted)*100, mean(h$fitted)*100 - mean(h$se.fitted)*100, mean(i$fitted)*100 - mean(i$se.fitted)*100, mean(j$fitted)*100 - mean(j$se.fitted)*100, mean(k$fitted)*100 - mean(k$se.fitted)*100, mean(l$fitted)*100 - mean(l$se.fitted)*100, mean(m$fitted)*100 - mean(m$se.fitted)*100, mean(n$fitted)*100 - mean(n$se.fitted)*100, mean(o$fitted)*100 - mean(o$se.fitted)*100, mean(p$fitted)*100 - mean(p$se.fitted)*100, mean(q$fitted)*100 - mean(q$se.fitted)*100, mean(r$fitted)*100 - mean(r$se.fitted)*100, mean(s$fitted)*100 - mean(s$se.fitted)*100, mean(t$fitted)*100 - mean(t$se.fitted)*100),
  upper = c(mean(a$fitted)*100 + mean(a$se.fitted)*100, mean(b$fitted)*100 + mean(b$se.fitted)*100, mean(c$fitted)*100 + mean(c$se.fitted)*100, mean(d$fitted)*100 + mean(d$se.fitted)*100, mean(e$fitted)*100 + mean(e$se.fitted)*100, mean(f$fitted)*100 + mean(f$se.fitted)*100, mean(g$fitted)*100 + mean(g$se.fitted)*100, mean(h$fitted)*100 + mean(h$se.fitted)*100, mean(i$fitted)*100 + mean(i$se.fitted)*100, mean(j$fitted)*100 + mean(j$se.fitted)*100, mean(k$fitted)*100 + mean(k$se.fitted)*100, mean(l$fitted)*100 + mean(l$se.fitted)*100, mean(m$fitted)*100 + mean(m$se.fitted)*100, mean(n$fitted)*100 + mean(n$se.fitted)*100, mean(o$fitted)*100 + mean(o$se.fitted)*100, mean(p$fitted)*100 + mean(p$se.fitted)*100, mean(q$fitted)*100 + mean(q$se.fitted)*100, mean(r$fitted)*100 + mean(r$se.fitted)*100, mean(s$fitted)*100 + mean(s$se.fitted)*100, mean(t$fitted)*100 + mean(t$se.fitted)*100),
  order = c(2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 1, 1, 1, 1, 1))

figure$Party <- factor(figure$Party, levels = unique(figure$Party))

ggplot(figure, aes(x= reorder(Treatment,order), y=avg, fill=Party)) +
  geom_bar(stat="identity", position="dodge", color= "black", width=.75) +
  geom_linerange(aes(ymin=lower, ymax=upper), position= position_dodge(.75)) +
  geom_text(aes(y=upper, label=round(avg,1)), size = 3, position=position_dodge(width=0.7), vjust=-1.75)+
  labs(y="Click Rate (%)", x="", title="", caption = "Note: Error bars represent ± 1 standard error (HC2)", size = 4)+
  scale_fill_manual(values=c("navy", "darkgreen","dodgerblue1","beige","palegreen3")) + 
  scale_y_continuous(limits = c(0, 60)) + theme_fira() + 
  theme(text = element_text(size=8), legend.position= "bottom", plot.caption = element_text(size = 6, color = "gray40", face = "italic"))

# Figure SI 7 - lower panel
summary(model_red <- lm_robust(click ~ cue*party_name, data = df_replication, se_type="HC2"))

a <- prediction(model_red, at = list(cue = "public_opinion", party_name = "Socialdemokratiet"))
b <- prediction(model_red, at = list(cue = "public_opinion", party_name = "Radikale Venstre"))
c <- prediction(model_red, at = list(cue = "public_opinion", party_name = "Socialistisk Folkeparti"))
d <- prediction(model_red, at = list(cue = "public_opinion", party_name = "Enhedslisten"))
e <- prediction(model_red, at = list(cue = "public_opinion", party_name = "Alternativet"))

f <- prediction(model_red, at = list(cue = "rival_parties", party_name = "Socialdemokratiet"))
g <- prediction(model_red, at = list(cue = "rival_parties", party_name = "Radikale Venstre"))
h <- prediction(model_red, at = list(cue = "rival_parties", party_name = "Socialistisk Folkeparti"))
i <- prediction(model_red, at = list(cue = "rival_parties", party_name = "Enhedslisten"))
j <- prediction(model_red, at = list(cue = "rival_parties", party_name = "Alternativet"))

k <- prediction(model_red, at = list(cue = "the_media", party_name = "Socialdemokratiet"))
l <- prediction(model_red, at = list(cue = "the_media", party_name = "Radikale Venstre"))
m <- prediction(model_red, at = list(cue = "the_media", party_name = "Socialistisk Folkeparti"))
n <- prediction(model_red, at = list(cue = "the_media", party_name = "Enhedslisten"))
o <- prediction(model_red, at = list(cue = "the_media", party_name = "Alternativet"))

p <- prediction(model_red, at = list(cue = "problem_indicators", party_name = "Socialdemokratiet"))
q <- prediction(model_red, at = list(cue = "problem_indicators", party_name = "Radikale Venstre"))
r <- prediction(model_red, at = list(cue = "problem_indicators", party_name = "Socialistisk Folkeparti"))
s <- prediction(model_red, at = list(cue = "problem_indicators", party_name = "Enhedslisten"))
t <- prediction(model_red, at = list(cue = "problem_indicators", party_name = "Alternativet"))

figure <- tibble(
  Party = c("Socialdemokratiet", "Radikale Venstre", "Socialistisk Folkeparti","Enhedslisten", "Alternativet","Socialdemokratiet", "Radikale Venstre", "Socialistisk Folkeparti","Enhedslisten", "Alternativet","Socialdemokratiet", "Radikale Venstre", "Socialistisk Folkeparti","Enhedslisten", "Alternativet","Socialdemokratiet", "Radikale Venstre", "Socialistisk Folkeparti","Enhedslisten", "Alternativet"),
  Treatment = c("Public Opinion", "Public Opinion", "Public Opinion", "Public Opinion", "Public Opinion", "Party Positions", "Party Positions", "Party Positions", "Party Positions", "Party Positions", "Media Reporting", "Media Reporting", "Media Reporting", "Media Reporting","Media Reporting",  "Problem Indicators","Problem Indicators", "Problem Indicators","Problem Indicators", "Problem Indicators"),
  avg = c(mean(a$fitted)*100, mean(b$fitted)*100, mean(c$fitted)*100, mean(d$fitted)*100, mean(e$fitted)*100, mean(f$fitted)*100, mean(g$fitted)*100, mean(h$fitted)*100, mean(i$fitted)*100, mean(j$fitted)*100, mean(k$fitted)*100, mean(l$fitted)*100, mean(m$fitted)*100, mean(n$fitted)*100, mean(o$fitted)*100, mean(p$fitted)*100, mean(q$fitted)*100, mean(r$fitted)*100, mean(s$fitted)*100, mean(t$fitted)*100), 
  lower = c(mean(a$fitted)*100 - mean(a$se.fitted)*100, mean(b$fitted)*100 - mean(b$se.fitted)*100, mean(c$fitted)*100 - mean(c$se.fitted)*100, mean(d$fitted)*100 - mean(d$se.fitted)*100, mean(e$fitted)*100 - mean(e$se.fitted)*100, mean(f$fitted)*100 - mean(f$se.fitted)*100, mean(g$fitted)*100 - mean(g$se.fitted)*100, mean(h$fitted)*100 - mean(h$se.fitted)*100, mean(i$fitted)*100 - mean(i$se.fitted)*100, mean(j$fitted)*100 - mean(j$se.fitted)*100, mean(k$fitted)*100 - mean(k$se.fitted)*100, mean(l$fitted)*100 - mean(l$se.fitted)*100, mean(m$fitted)*100 - mean(m$se.fitted)*100, mean(n$fitted)*100 - mean(n$se.fitted)*100, mean(o$fitted)*100 - mean(o$se.fitted)*100, mean(p$fitted)*100 - mean(p$se.fitted)*100, mean(q$fitted)*100 - mean(q$se.fitted)*100, mean(r$fitted)*100 - mean(r$se.fitted)*100, mean(s$fitted)*100 - mean(s$se.fitted)*100, mean(t$fitted)*100 - mean(t$se.fitted)*100),
  upper = c(mean(a$fitted)*100 + mean(a$se.fitted)*100, mean(b$fitted)*100 + mean(b$se.fitted)*100, mean(c$fitted)*100 + mean(c$se.fitted)*100, mean(d$fitted)*100 + mean(d$se.fitted)*100, mean(e$fitted)*100 + mean(e$se.fitted)*100, mean(f$fitted)*100 + mean(f$se.fitted)*100, mean(g$fitted)*100 + mean(g$se.fitted)*100, mean(h$fitted)*100 + mean(h$se.fitted)*100, mean(i$fitted)*100 + mean(i$se.fitted)*100, mean(j$fitted)*100 + mean(j$se.fitted)*100, mean(k$fitted)*100 + mean(k$se.fitted)*100, mean(l$fitted)*100 + mean(l$se.fitted)*100, mean(m$fitted)*100 + mean(m$se.fitted)*100, mean(n$fitted)*100 + mean(n$se.fitted)*100, mean(o$fitted)*100 + mean(o$se.fitted)*100, mean(p$fitted)*100 + mean(p$se.fitted)*100, mean(q$fitted)*100 + mean(q$se.fitted)*100, mean(r$fitted)*100 + mean(r$se.fitted)*100, mean(s$fitted)*100 + mean(s$se.fitted)*100, mean(t$fitted)*100 + mean(t$se.fitted)*100),
  order = c(2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 1, 1, 1, 1, 1))

figure$Party <- factor(figure$Party, levels = unique(figure$Party))

ggplot(figure, aes(x= reorder(Treatment,order), y=avg, fill=Party)) +
  geom_bar(stat="identity", position="dodge", color= "black", width=.65) +
  geom_linerange(aes(ymin=lower, ymax=upper), position= position_dodge(.65)) +
  geom_text(aes(y=upper, label=round(avg,1)), size = 3, position=position_dodge(width=0.7), vjust=-1.75)+
  labs(y="Click Rate (%)", x="", title="", caption = "Note: Error bars represent ± 1 standard error (HC2)", size = 4)+
  scale_fill_manual(values=c("#f04d46","#EC008C","darkred", "#D0004D","#00FF00")) + 
  scale_y_continuous(limits = c(0, 60)) + theme_fira() + 
  theme(text = element_text(size=8), legend.position= "bottom", plot.caption = element_text(size = 6, color = "gray40", face = "italic"))



# Figure SI 8 - upper panel
model_blue2 <- lm_robust(click ~ cue + issue*party_name, data = df_replication, se_type="HC2")

# blue parties
a <- prediction(model_blue2, at = list(issue = "school", party_name = "Venstre"))
b <- prediction(model_blue2, at = list(issue = "school", party_name = "Konservative"))
c <- prediction(model_blue2, at = list(issue = "school", party_name = "Dansk Folkeparti"))
d <- prediction(model_blue2, at = list(issue = "school", party_name = "Liberal Alliance"))
e <- prediction(model_blue2, at = list(issue = "school", party_name = "Nye Borgerlige"))

f <- prediction(model_blue2, at = list(issue = "climate", party_name = "Venstre"))
g <- prediction(model_blue2, at = list(issue = "climate", party_name = "Konservative"))
h <- prediction(model_blue2, at = list(issue = "climate", party_name = "Dansk Folkeparti"))
i <- prediction(model_blue2, at = list(issue = "climate", party_name = "Liberal Alliance"))
j <- prediction(model_blue2, at = list(issue = "climate", party_name = "Nye Borgerlige"))

figure <- tibble(
  Party = c("Venstre", "Konservative", "Dansk Folkeparti", "Liberal Alliance", "Nye Borgerlige", "Venstre", "Konservative", "Dansk Folkeparti", "Liberal Alliance", "Nye Borgerlige"),
  Treatment = c("school", "school", "school", "school", "school", "climate", "climate", "climate", "climate", "climate"),
  avg = c(mean(a$fitted)*100, mean(b$fitted)*100, mean(c$fitted)*100, mean(d$fitted)*100, mean(e$fitted)*100, mean(f$fitted)*100, mean(g$fitted)*100, mean(h$fitted)*100, mean(i$fitted)*100, mean(j$fitted)*100), 
  lower = c(mean(a$fitted)*100 - mean(a$se.fitted)*100, mean(b$fitted)*100 - mean(b$se.fitted)*100, mean(c$fitted)*100 - mean(c$se.fitted)*100, mean(d$fitted)*100 - mean(d$se.fitted)*100, mean(e$fitted)*100 - mean(e$se.fitted)*100, mean(f$fitted)*100 - mean(f$se.fitted)*100, mean(g$fitted)*100 - mean(g$se.fitted)*100, mean(h$fitted)*100 - mean(h$se.fitted)*100, mean(i$fitted)*100 - mean(i$se.fitted)*100, mean(j$fitted)*100 - mean(j$se.fitted)*100),
  upper = c(mean(a$fitted)*100 + mean(a$se.fitted)*100, mean(b$fitted)*100 + mean(b$se.fitted)*100, mean(c$fitted)*100 + mean(c$se.fitted)*100, mean(d$fitted)*100 + mean(d$se.fitted)*100, mean(e$fitted)*100 + mean(e$se.fitted)*100, mean(f$fitted)*100 + mean(f$se.fitted)*100, mean(g$fitted)*100 + mean(g$se.fitted)*100, mean(h$fitted)*100 + mean(h$se.fitted)*100, mean(i$fitted)*100 + mean(i$se.fitted)*100, mean(j$fitted)*100 + mean(j$se.fitted)*100),
  order = c(2, 2, 2, 2, 2, 1, 1, 1, 1, 1))

figure$Party <- factor(figure$Party, levels = unique(figure$Party))

ggplot(figure, aes(x= reorder(Treatment,order), y=avg, fill=Party)) +
  geom_bar(stat="identity", position="dodge", color= "black", width=.75) +
  geom_linerange(aes(ymin=lower, ymax=upper), position= position_dodge(.75)) +
  geom_text(aes(y=upper, label=round(avg,1)), size = 3, position=position_dodge(width=0.7), vjust=-1.75)+
  labs(y="Click Rate (%)", x="", title="", caption = "Note: Error bars represent ± 1 standard error (HC2)", size = 4)+
  scale_fill_manual(values=c("navy", "darkgreen","dodgerblue1","beige","palegreen3")) + 
  scale_y_continuous(limits = c(0, 45)) + theme_fira() + 
  theme(text = element_text(size=8), legend.position= "bottom", plot.caption = element_text(size = 6, color = "gray40", face = "italic"))


# Figure SI 8 - lower panel
model_red2 <- lm_robust(click ~ cue + issue*party_name, data = df_replication, se_type="HC2")

a <- prediction(model_red2, at = list(issue = "school", party_name = "Socialdemokratiet"))
b <- prediction(model_red2, at = list(issue = "school", party_name = "Radikale Venstre"))
c <- prediction(model_red2, at = list(issue = "school", party_name = "Socialistisk Folkeparti"))
d <- prediction(model_red2, at = list(issue = "school", party_name = "Enhedslisten"))
e <- prediction(model_red2, at = list(issue = "school", party_name = "Alternativet"))

f <- prediction(model_red2, at = list(issue = "climate", party_name = "Socialdemokratiet"))
g <- prediction(model_red2, at = list(issue = "climate", party_name = "Radikale Venstre"))
h <- prediction(model_red2, at = list(issue = "climate", party_name = "Socialistisk Folkeparti"))
i <- prediction(model_red2, at = list(issue = "climate", party_name = "Enhedslisten"))
j <- prediction(model_red2, at = list(issue = "climate", party_name = "Alternativet"))

figure <- tibble(
  Party = c("Socialdemokratiet", "Radikale Venstre", "Socialistisk Folkeparti","Enhedslisten", "Alternativet", "Socialdemokratiet", "Radikale Venstre", "Socialistisk Folkeparti","Enhedslisten", "Alternativet"),
  Treatment = c("school", "school", "school", "school", "school", "climate", "climate", "climate", "climate", "climate"),
  avg = c(mean(a$fitted)*100, mean(b$fitted)*100, mean(c$fitted)*100, mean(d$fitted)*100, mean(e$fitted)*100, mean(f$fitted)*100, mean(g$fitted)*100, mean(h$fitted)*100, mean(i$fitted)*100, mean(j$fitted)*100), 
  lower = c(mean(a$fitted)*100 - mean(a$se.fitted)*100, mean(b$fitted)*100 - mean(b$se.fitted)*100, mean(c$fitted)*100 - mean(c$se.fitted)*100, mean(d$fitted)*100 - mean(d$se.fitted)*100, mean(e$fitted)*100 - mean(e$se.fitted)*100, mean(f$fitted)*100 - mean(f$se.fitted)*100, mean(g$fitted)*100 - mean(g$se.fitted)*100, mean(h$fitted)*100 - mean(h$se.fitted)*100, mean(i$fitted)*100 - mean(i$se.fitted)*100, mean(j$fitted)*100 - mean(j$se.fitted)*100),
  upper = c(mean(a$fitted)*100 + mean(a$se.fitted)*100, mean(b$fitted)*100 + mean(b$se.fitted)*100, mean(c$fitted)*100 + mean(c$se.fitted)*100, mean(d$fitted)*100 + mean(d$se.fitted)*100, mean(e$fitted)*100 + mean(e$se.fitted)*100, mean(f$fitted)*100 + mean(f$se.fitted)*100, mean(g$fitted)*100 + mean(g$se.fitted)*100, mean(h$fitted)*100 + mean(h$se.fitted)*100, mean(i$fitted)*100 + mean(i$se.fitted)*100, mean(j$fitted)*100 + mean(j$se.fitted)*100),
  order = c(2, 2, 2, 2, 2, 1, 1, 1, 1, 1))

figure$Party <- factor(figure$Party, levels = unique(figure$Party))

ggplot(figure, aes(x= reorder(Treatment,order), y=avg, fill=Party)) +
  geom_bar(stat="identity", position="dodge", color= "black", width=.65) +
  geom_linerange(aes(ymin=lower, ymax=upper), position= position_dodge(.65)) +
  geom_text(aes(y=upper, label=round(avg,1)), size = 3, position=position_dodge(width=0.7), vjust=-1.75)+
  labs(y="Click Rate (%)", x="", title="", caption = "Note: Error bars represent ± 1 standard error (HC2)", size = 4)+
  scale_fill_manual(values=c("#f04d46","#EC008C","darkred", "#D0004D","#00FF00")) + 
  scale_y_continuous(limits = c(0, 50)) + theme_fira() + 
  theme(text = element_text(size=8), legend.position= "bottom", plot.caption = element_text(size = 6, color = "gray40", face = "italic"))